package test.tij.chapter3.typesize;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class TypeSize
{
	/**
	 * @param args
	 *            <ol>
	 *            <li>
	 *            you can't give a value more than the variable type can accept
	 *            have to cast, that means give the value to a another type and
	 *            cast to this type. <\li>
	 *            <li>
	 *            short max allowed data starts with 7, while int max allowed
	 *            data starts with f Java does not support unsigned types. char
	 *            0~65536 short -32768~32767 <\li>
	 *            <li>
	 *            因为oxffff是int类型，超出了short类型最大值，进行int到short转换时会造成精度丢失，编译报错
	 *            而oxffffffff尽管超出了int类型最大值，但是他还是int型，不需要转换，编译不报错，只是数据不正确。
	 * 
	 *            如果int a = oxfffffffffL,由long型转换为int，也会编译报错。
	 * 
	 *            Assignment(Not Initial) with type case, won't result in an
	 *            error.<\li>
	 *            </ol>
	 * @throws UnknownHostException
	 */
	
	private static char cc;
	
	public static void main(String[] args) throws UnknownHostException
	{
//		System.out.println(System.getProperty("file.encoding"));
		
		int i = 0xffffffff;
		byte b = 0x7f; // decimal we can assign -128~127
		short s = 0x7fff; // decimal we can assign -32768~32767
		short s1 = (short) 0xffff;
		char c = 0xffff; // decimal we can assign 0~65535
		char c1 = new Character((char) -1);
		char c2 = 0;
		
		System.out.println("int i = 0xffffffff		" + i);
		System.out.println("byte b = 0x7f;			" + b);
		System.out.println("short s = 0x7fff;		" + s);
		System.out.println("short s1 = (short) 0xffff;	" + s1);
		System.out.println("char c = 0xffff;		" + c);
		System.out.println("new Character((char) -1)	"
				+ new Character((char) -1));
		System.out.println("new Character((char) 32768)	"
				+ new Character((char) 32768));
		System.out.println("new Character((char) 65536)	"
				+ new Character((char) 65536));

		System.out.println(c==c1);
		System.out.println(c==c2);
		System.out.println(c1==c2);
		System.out.println(c==cc);
		System.out.println(c2==cc);
		
		float f = 1.0f;
		double d = (double) f;
		f = (float) d;

		b = (byte) (b + 200); //

		// String hostName = "www.baidu.cn";
		// // getByName接收的是主机名，而不是URL，主机名只是URL的一部分,hostName 不含 http://
		// InetAddress addr = InetAddress.getByName(hostName);
		// System.out.println(addr.getHostAddress());
	}
}
